<?php
/**
 * Created by PhpStorm.
 * User: Admin
 * Date: 2021/12/25
 * Time: 16:18
 */

namespace app\admin\controller;

use app\admin\model\OpenEggDetail;
use app\common\CacheKey;
use think\Db;

class OpenEgg extends AdminBase
{
    public function egglist()
    {
        $data = OpenEggDetail::getInstance()->getList();

        $this->assign("data", $data['data']);
        $this->assign("page", $data['page']);
        $this->assign("keywords", input('param.keywords', ''));
        $this->assign("range", input('param.range', ''));
        $this->assign("type", input('param.type'));
        $this->assign("is_give", input('param.is_give'));

        return $this->fetch();
    }

    /**
     * @Title: export
     * @Describe
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     * @author lijunwei
     * @Date 2022/1/6 14:32
     */
    public function export()
    {
        $lists = OpenEggDetail::getInstance()->exportExcel();
        $result = [];
        foreach ($lists as $key => $list) {
            if ($list['type'] == 0) {
                $egg = '银蛋';
            } else {
                $egg = '金蛋';
            }
            if ($list['is_give'] == 0) {
                $is_give = '不是';
            } else {
                $is_give = '是';
            }
            $result[$key] = [
                'id' => $list['id'],
                'add_time' => $list['add_time'],
                'user_address' => $list['user_address'],
                'type' => $egg,
                'is_give' => $is_give,
                'trans_price' => $list['trans_price'],
                'egg_result' => $list['egg_result'],
                'nft_id' => $list['nft_id'],
            ];
        }
        $header = [
            'A' => [
                'title' => '开蛋ID',
                'value' => 'id',
            ],
            'B' => [
                'title' => '开蛋时间',
                'value' => 'add_time',
            ],
            'C' => [
                'title' => '用户地址',
                'value' => 'user_address',
            ],
            'D' => [
                'title' => '类型',
                'value' => 'type',
            ],
            'E' => [
                'title' => '是否为赠送',
                'value' => 'is_give',
            ],
            'F' => [
                'title' => '成交价(DIN)',
                'value' => 'trans_price',
            ],
            'G' => [
                'title' => '开蛋结果',
                'value' => 'egg_result',
            ],
            'H' => [
                'title' => '恐龙NFT ID',
                'value' => 'nft_id',
            ]
        ];
        $name = '开蛋明细';

        outExcel($result, $header, $name);
    }
}